/*
 * @Author: your name
 * @Date: 2021-09-09 13:12:49
 * @LastEditTime: 2021-09-09 18:39:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \quntuan\mixins\news-1.js
 */
import { getDictItemstList } from '@/api/dict'
export const news1 = {
  data() {
    return {
      elegantIndex:0,//
      elegantTab: 0, //风采导航第几项
      elegantList: [], //风采导航名称
      staticList: [
        {
          cate_name: '视频',
          newsType: '-99',
          type: '-99',
          isShow: false,
          index: 0, // 映射tabIndex
        },
        {
          cate_name: '直播',
          newsType: '-99',
          type: '-99',
          isShow: false,
          index: 1, // 映射tabIndex
        },
      ],
    }
  },
  methods: {
    //新闻风采分类
    getNewsDictItemstList(type) {
      const plist = []
      getDictItemstList({ dictCode: 'news_type' })
        .then((res) => {
          const { code, result } = res
          if (code === 0 || code === 200) {
            result.map((item) => {
              const { title, value } = item
              plist.push({
                cate_name: title,
                newsType: value,
                type: value,
              })
            })
            if (type === 'a') {
              // plist.push ({
              //   cate_name: '视频直播' , newsType: '-99' , type: '-99' , isShow: false
              // })
              /**
               * @author 2U
               * @description 调整tab
               */
              const index = plist.findIndex((item) => {
                return item.cate_name == '最新动态'
              })
              plist.splice(index + 1, 0, ...this.staticList)
            }
            this.elegantList = plist
            if (this.elegantList.length) {
              this.getNewsList(this.elegantList[this.elegantTab].newsType)
            }
          }
        })
        .catch((e) => {
          console.log(e)
        })
    },
    //风采点击分类
    onTabelegantTabClick(index,item) {
      let abcIndex=0
      console.log ( item )
      abcIndex = this.elegantList.findIndex(items=>items.code===item.code);
      this.elegantIndex =item.type || 0

      this.elegantTab = index
      if(this.elegantList[this.elegantTab].types===-1){
        if(this.elegantList[this.elegantTab].code==='498'){
          this.$api.handleMenu(`/pages/liveVideo/liveVideo`)
        } else if(this.elegantList[this.elegantTab].code==='499'){
          this.$api.handleMenu(`/pages/liveActivity/liveActivity`)
        }else {
          this.getNewsList( this.elegantList[this.elegantTab].newsType)
        }
      } else {
        const newsType = this.elegantList[this.elegantTab].newsType
        if (newsType === '-99') {
          //进入视频直播
          const tabIndex = this.elegantList[this.elegantTab].index
          tabIndex === 0
            ? this.$api.handleMenu(`/pages/liveVideo/liveVideo`)
            :  this.$api.handleMenu(`/pages/liveActivity/liveActivity`)
          this.elegantTab = 0
        } else {
          this.getNewsList(newsType)
        }
      }

    },
  },
}
